<?php


namespace app\api\controller;


use think\Controller;
use think\controller\Rest;
use think\Db;
use think\Request;

class Food extends Controller
{
    public function foodList()
    {
        $result = Db::name("t_foods")->where(["data_state" => 1])->select();
        $count = Db::name("t_foods")->where(["data_state" => 1])->count();
        if ($result) {
            $data = [
                "msg" => "成功",
                "success" => true,
                "list" => $result
            ];
            return $data;
        } else {
            if ($count == 0){
                $data = [
                    "msg" => "暂无数据",
                    "success" => false
                ];
                return $data;
            }
            $data = [
                "msg" => "失败",
                "success" => false
            ];
            return $data;
        }
    }

    public function findone()
    {
        $request = Request::instance();
        $data = $request->param();
        $result = Db::name("t_foods")->where(["id" => $data["id"]])->find();
        if ($result) {
            $data = [
                "msg" => "成功",
                "success" => true,
                "data" => $result
            ];
            return $data;
        } else {
            $data = [
                "msg" => "失败",
                "success" => false
            ];
            return $data;
        }
    }
}